package com.yuexunit.finance.system.service;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.yuexunit.finance.seal.entity.lexion.SignStateEnum;
import com.yuexunit.finance.system.entity.SignFileSealInfoEntity;
import com.yuexunit.inject.annotation.Implements;
import com.yuexunit.page.PageCriteria;
import com.yuexunit.page.PageList;
import com.yuexunit.persist.PersistUtil;
import com.yuexunit.persist.annotation.Transactional;
import com.yuexunit.util.DateUtil;
import com.yuexunit.util.StringUtil;

/**
*@version 创建时间：2017年5月29日 下午12:48:12
*@author wenwenlong
*类说明
*/

@Implements(SignFileSealInfoService.class)
public class SignFileSealInfoServiceImpl implements SignFileSealInfoService {

	@Override
	@Transactional
	public Long createSignFileSealInfo(SignFileSealInfoEntity entity) {
		entity.setUpdateDateTime(DateUtil.now());
		entity.setSignState(SignStateEnum.WAIT_SIGN);
		PersistUtil.insert(entity);
		return entity.getSignFileSealId();
	}

	@Override
	@Transactional
	public void updateSignFileSealInfo(SignFileSealInfoEntity entity) {
		entity.setUpdateDateTime(DateUtil.now());
		PersistUtil.update(entity);
	}
	
	@Override
	public SignFileSealInfoEntity inquireSignFileSealInfo(Long signFileSealId) {
		if (null == signFileSealId) {
			return null;
		}
		return PersistUtil.get(SignFileSealInfoEntity.class, signFileSealId);
	}
	
	@Override
	@Transactional
	public void deleteSignFileSealInfo(Long signFileSealId) {
		PersistUtil.delete(SignFileSealInfoEntity.class, signFileSealId);
	}

	@Override
	public List<SignFileSealInfoEntity> inquireSignFileSealInfoList(String fileUuid, SignStateEnum signState, Integer creatorType) {
		DetachedCriteria criteria = DetachedCriteria.forClass(SignFileSealInfoEntity.class);
		criteria.add(Restrictions.eq("fileUuid", fileUuid));
		if (signState != null) {
			criteria.add(Restrictions.eq("signState", signState));
		}
		if (creatorType != null) {
			criteria.add(Restrictions.eq("creatorType", creatorType));
		}
		return PersistUtil.get(criteria);
	}

	@Override
	public PageList<SignFileSealInfoEntity> inquireSignFileSealInfoPageList(String fileUuid, Integer creatorType, SignStateEnum signState, PageCriteria page) {
		DetachedCriteria criteria = DetachedCriteria.forClass(SignFileSealInfoEntity.class);
		if (StringUtil.isNotBlank(fileUuid)) {
			criteria.add(Restrictions.eq("fileUuid", fileUuid));
		}
		if (creatorType != null) {
			criteria.add(Restrictions.eq("creatorType", creatorType));
		}
		if (signState != null) {
			criteria.add(Restrictions.eq("signState", signState));
		}
		return PersistUtil.get(criteria, page);
	}
}
